package com.me.hippy.sdk.demo.chat;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.os.Build;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import java.lang.reflect.Method;

/* renamed from: com.mosheng.common.view.j */
public class SystemStatusManager {
    /* access modifiers changed from: private */

    /* renamed from: f */
    public static String f29541f;

    /* renamed from: a */
    private final C7482b f29542a;

    /* renamed from: b */
    private boolean f29543b;

    /* renamed from: c */
    private boolean f29544c;

    /* renamed from: d */
    private View f29545d;

    /* renamed from: e */
    private View f29546e;

    static {
        if (Build.VERSION.SDK_INT >= 19) {
            try {
                Method declaredMethod = Class.forName("android.os.SystemProperties").getDeclaredMethod("get", new Class[]{String.class});
                declaredMethod.setAccessible(true);
                f29541f = (String) declaredMethod.invoke((Object) null, new Object[]{"qemu.hw.mainkeys"});
            } catch (Throwable unused) {
                f29541f = null;
            }
        }
    }

    /* JADX INFO: finally extract failed */
    @TargetApi(19)
    public SystemStatusManager(Activity activity) {
        FrameLayout.LayoutParams layoutParams;
        Window window = activity.getWindow();
        ViewGroup viewGroup = (ViewGroup) window.getDecorView();
        if (Build.VERSION.SDK_INT >= 19) {
            TypedArray obtainStyledAttributes = activity.obtainStyledAttributes(new int[]{16843759, 16843760});
            try {
                this.f29543b = obtainStyledAttributes.getBoolean(0, false);
                this.f29544c = obtainStyledAttributes.getBoolean(1, false);
                obtainStyledAttributes.recycle();
                WindowManager.LayoutParams attributes = window.getAttributes();
                if ((67108864 & attributes.flags) != 0) {
                    this.f29543b = true;
                }
                if ((attributes.flags & 134217728) != 0) {
                    this.f29544c = true;
                }
            } catch (Throwable th) {
                obtainStyledAttributes.recycle();
                throw th;
            }
        }
        this.f29542a = new C7482b(activity, this.f29543b, this.f29544c,  null);
        if (!this.f29542a.mo57456d()) {
            this.f29544c = false;
        }
        if (this.f29543b) {
            this.f29545d = new View(activity);
            FrameLayout.LayoutParams layoutParams2 = new FrameLayout.LayoutParams(-1, this.f29542a.mo57455c());
            layoutParams2.gravity = 48;
            if (this.f29544c && !this.f29542a.mo57457e()) {
                layoutParams2.rightMargin = this.f29542a.mo57454b();
            }
            this.f29545d.setLayoutParams(layoutParams2);
            this.f29545d.setBackgroundColor(-1728053248);
            this.f29545d.setVisibility(View.GONE);
            viewGroup.addView(this.f29545d);
        }
        if (this.f29544c) {
            this.f29546e = new View(activity);
            if (this.f29542a.mo57457e()) {
                layoutParams = new FrameLayout.LayoutParams(-1, this.f29542a.mo57453a());
                layoutParams.gravity = 80;
            } else {
                layoutParams = new FrameLayout.LayoutParams(this.f29542a.mo57454b(), -1);
                layoutParams.gravity = 5;
            }
            this.f29546e.setLayoutParams(layoutParams);
            this.f29546e.setBackgroundColor(-1728053248);
            this.f29546e.setVisibility(View.GONE);
            viewGroup.addView(this.f29546e);
        }
    }

    /* renamed from: a */
    public boolean mo57452a() {
        return this.f29543b;
    }

    /* renamed from: a */
    public void mo57451a(boolean z) {
        if (this.f29543b) {
            this.f29545d.setVisibility(z ? View.VISIBLE : View.GONE);
        }
    }

    /* renamed from: a */
    public void mo57450a(int i) {
        if (this.f29543b) {
            this.f29545d.setBackgroundResource(i);
        }
    }

    /* renamed from: com.mosheng.common.view.j$b */
    /* compiled from: SystemStatusManager */
    public static class C7482b {

        /* renamed from: a */
        private final int f29547a;

        /* renamed from: b */
        private final boolean f29548b;

        /* renamed from: c */
        private final int f29549c;

        /* renamed from: d */
        private final int f29550d;

        /* renamed from: e */
        private final boolean f29551e;

        /* renamed from: f */
        private final float f29552f;

        /* synthetic */ C7482b(Activity activity, boolean z, boolean z2, Object aVar) {
            int i;
            Resources resources = activity.getResources();
            boolean z3 = true;
            this.f29551e = resources.getConfiguration().orientation == 1;
            DisplayMetrics displayMetrics = new DisplayMetrics();
            int i2 = Build.VERSION.SDK_INT;
            activity.getWindowManager().getDefaultDisplay().getRealMetrics(displayMetrics);
            float f = displayMetrics.density;
            this.f29552f = Math.min(((float) displayMetrics.widthPixels) / f, ((float) displayMetrics.heightPixels) / f);
            this.f29547a = m33240a(resources, "status_bar_height");
            int i3 = Build.VERSION.SDK_INT;
            TypedValue typedValue = new TypedValue();
            activity.getTheme().resolveAttribute(16843499, typedValue, true);
            TypedValue.complexToDimensionPixelSize(typedValue.data, activity.getResources().getDisplayMetrics());
            Resources resources2 = activity.getResources();
            int i4 = Build.VERSION.SDK_INT;
            if (m33241a(activity)) {
                i = m33240a(resources2, this.f29551e ? "navigation_bar_height" : "navigation_bar_height_landscape");
            } else {
                i = 0;
            }
            this.f29549c = i;
            Resources resources3 = activity.getResources();
            int i5 = Build.VERSION.SDK_INT;
            this.f29550d = m33241a(activity) ? m33240a(resources3, "navigation_bar_width") : 0;
            this.f29548b = this.f29549c <= 0 ? false : z3;
        }

        @TargetApi(14)
        /* renamed from: a */
        private boolean m33241a(Context context) {
            Resources resources = context.getResources();
            int identifier = resources.getIdentifier("config_showNavigationBar", "bool", "android");
            if (identifier == 0) {
                return !ViewConfiguration.get(context).hasPermanentMenuKey();
            }
            boolean z = resources.getBoolean(identifier);
            if ("1".equals(SystemStatusManager.f29541f)) {
                return false;
            }
            if ("0".equals(SystemStatusManager.f29541f)) {
                return true;
            }
            return z;
        }

        /* renamed from: b */
        public int mo57454b() {
            return this.f29550d;
        }

        /* renamed from: c */
        public int mo57455c() {
            return this.f29547a;
        }

        /* renamed from: d */
        public boolean mo57456d() {
            return this.f29548b;
        }

        /* renamed from: e */
        public boolean mo57457e() {
            return this.f29552f >= 600.0f || this.f29551e;
        }

        /* renamed from: a */
        private int m33240a(Resources resources, String str) {
            int identifier = resources.getIdentifier(str, "dimen", "android");
            if (identifier > 0) {
                return resources.getDimensionPixelSize(identifier);
            }
            return 0;
        }

        /* renamed from: a */
        public int mo57453a() {
            return this.f29549c;
        }
    }
}
